/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package dreamwar.model.POJO;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Berto_Romero
 */
@Entity
@Table(name = "weapon")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Weapon.findAll", query = "SELECT w FROM Weapon w"),
    @NamedQuery(name = "Weapon.findByIdWeapon", query = "SELECT w FROM Weapon w WHERE w.idWeapon = :idWeapon"),
    @NamedQuery(name = "Weapon.findByWeaponName", query = "SELECT w FROM Weapon w WHERE w.weaponName = :weaponName"),
    @NamedQuery(name = "Weapon.findByStrength", query = "SELECT w FROM Weapon w WHERE w.strength = :strength"),
    @NamedQuery(name = "Weapon.findByCloseRange", query = "SELECT w FROM Weapon w WHERE w.closeRange = :closeRange"),
    @NamedQuery(name = "Weapon.findByLongRange", query = "SELECT w FROM Weapon w WHERE w.longRange = :longRange")})
public class Weapon implements Serializable {
    @Transient
    private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id_weapon")
    private Integer idWeapon;
    @Column(name = "weapon_name")
    private String weaponName;
    @Column(name = "strength")
    private Integer strength;
    @Column(name = "close_range")
    private Integer closeRange;
    @Column(name = "long_range")
    private Integer longRange;
    @ManyToMany(mappedBy = "weaponCollection")
    private Collection<Feature> featureCollection;
    
    public Weapon() {
    }

    public Weapon(Integer idWeapon) {
        this.idWeapon = idWeapon;
    }

    public Integer getIdWeapon() {
        return idWeapon;
    }

    public void setIdWeapon(Integer idWeapon) {
        Integer oldIdWeapon = this.idWeapon;
        this.idWeapon = idWeapon;
        changeSupport.firePropertyChange("idWeapon", oldIdWeapon, idWeapon);
    }

    public String getWeaponName() {
        return weaponName;
    }

    public void setWeaponName(String weaponName) {
        String oldWeaponName = this.weaponName;
        this.weaponName = weaponName;
        changeSupport.firePropertyChange("weaponName", oldWeaponName, weaponName);
    }

    public Integer getStrength() {
        return strength;
    }

    public void setStrength(Integer strength) {
        Integer oldStrength = this.strength;
        this.strength = strength;
        changeSupport.firePropertyChange("strength", oldStrength, strength);
    }

    public Integer getCloseRange() {
        return closeRange;
    }

    public void setCloseRange(Integer closeRange) {
        Integer oldCloseRange = this.closeRange;
        this.closeRange = closeRange;
        changeSupport.firePropertyChange("closeRange", oldCloseRange, closeRange);
    }

    public Integer getLongRange() {
        return longRange;
    }

    public void setLongRange(Integer longRange) {
        Integer oldLongRange = this.longRange;
        this.longRange = longRange;
        changeSupport.firePropertyChange("longRange", oldLongRange, longRange);
    }

    @XmlTransient
    public Collection<Feature> getFeatureCollection() {
        return featureCollection;
    }

    public void setFeatureCollection(Collection<Feature> featureCollection) {
        this.featureCollection = featureCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idWeapon != null ? idWeapon.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Weapon)) {
            return false;
        }
        Weapon other = (Weapon) object;
        if ((this.idWeapon == null && other.idWeapon != null) || (this.idWeapon != null && !this.idWeapon.equals(other.idWeapon))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "dreamwar.model.POJO.Weapon[ idWeapon=" + idWeapon + " ]";
    }
    
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
    private class FeatureCollection extends AbstractCollection<Feature> {

        @Override
        public Iterator<Feature> iterator() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public int size() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public String toString() {
            StringBuilder featureListNames = new StringBuilder();
            for (Feature feature : this) {
                featureListNames.append(feature.getFeatureName());
                featureListNames.append(", ");
            }
            return featureListNames.substring(0, featureListNames.length() - 2);
        }
    }
}
